package pro.cherish.knowledgeumldesignpattern.designPattern.com.cherish.observer;

import java.util.ArrayList;
import java.util.List;

public class Subject {
    protected List<Observer> observerList = new ArrayList<>();

    public void register(Observer observer) {
        this.observerList.add(observer);
    }

    public void removeObserver(Observer observer) {
        this.observerList.remove(observer);
    }

    //    通知所有的观察者更新状态
    public void notifyAllObservers() {
        for (Observer o : observerList) {
            o.update(this);
        }
    }
}
